<?php
	/**
	 * <version greek="beta" major="1" minor="0">Cochin Splash Hen</version>
	 * <author email="njones@art-k-tec.com">Nika Jones</author>
	 * <copyright start="2007">Art-k-tec Systems, LLC</copyright>
	 * <license type="Apache2.0" href="http://www.opensource.org/licenses/apache2.0.php">Apache License, Version 2.0</license>
	 */
	class bSetException {}
	
	class bSet implements Countable {
		private static $nMajor =1;
		private static $nMinor =0;
		private static $sRevision ="0000";
		
		protected $aData; // uses array for base storage
		
		public function __construct() {
			
			$this->aData =array();
		}
		
		public static function version() { return self::$nMajor.'.'.self::$nMinor.'.'.self::$sRevision; }
	
		///<summary>
		///   Adds only one of any object or string to the array
		///</summary>
		///<returns type="bool"><true> if successful, and <false> if not</returns>
		public function Add($mData) {
			
			if($this->Contains($mData)) {
				
				return false;
			}
			
			$this->aData[$this->Hash($mData)] =$mData;

			return true;
		}
	
		///<summary>
		///   Checks to see if an same object exists within the set currently
		///</summary>
		///<returns type="bool" />
		public function Contains($mData) {
			$sHash =$this->Hash($mData);

			return isset($this->aData[$sHash]);
		}
	
		///<summary>
		///  Removes an item from the set
		///</summary>
		///<returns type="bool" />
		public function Remove($mData) {

			unset($this->aData[$this->Hash($mData)]);
			
			return true;
		}
	
		///<summary>
		///   Gives a count of the items in the set
		///</summary>
		///<returns type="int" />
		public function count() { 
			
			return count($this->aData);
		}
	
		///<summary>
		///   Erases everything from the set.
		///</summary>
		///<returns type="bool" />
		public function Clear() { 
			$this->aData =array();
			
			return true;
		}

		///<summary>
		///   Checks to see if the set is empty
		///</summary>
		///<returns type="bool" />
		public function IsEmpty() {
			
			return (count($this->aData) > 0 ? true : false);
		}
	
		///<summary>
		///   Returns the items within the set.
		///</summary>
		///<returns type="array" />
		public function Set() {
			
			return array_values($this->aData);
		} 
		
		///<summary>
		///   Creates a hash to compare items aginst to see if they are in the set
		///   currently or not.
		///</summary>
		///<returns type="string">The item hash</returns>
		private function Hash($mData) {
			
			if(is_object($mData)) {
				
				$sHash =spl_object_hash($mData);
			} else {
				
				$sHash =md5(serialize($mData));
			}
			
			return $sHash;
		}
	}
?>